﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jumpton.Data;

namespace Jumpton.SFA.Server.BusinessRule
{
    public class VersionManager
    {
        public string GetVersion_Info(string LoginName,string Password)
        {
            string _VersionName="";
            string[] param=new string[]{LoginName,Password};
            string SQL = string.Format(" select VersionName from Version "
            + " where IsActive='1' and VersionID=(select VersionID from VersionPublish where "
            + " IsActive='1' and EMP_ID=(select EMPLOYEE_ID from SYS_LOGIN_DATA where ACTIVE='1' and platform= "
            + " and LOGINNAME='{2}' and PASSWORD='{3}')) and versionname>'1.02'", param);
            IDataReader read = SqlData.ExecuteReader(SQL);
            while (read.Read())
            {
                _VersionName = read["VersionName"].ToString();
            }
            if (!String.IsNullOrEmpty(_VersionName))
            {
                read.Close();
            }
            else
            {
                SQL = string.Format(" select VersionName from Version where IsActive='1' and "
                + " VersionID=(select VersionID from VersionPublish where IsActive='1' and DEPT_id= "
                + " (select Department_id from EMPLOYEE where ACTIVE='1' and EMPLOYEE_ID= "
                + " (select EMPLOYEE_ID from SYS_LOGIN_DATA where ACTIVE='1' and LOGINNAME='{0}' "
                + " and PASSWORD='{1}'))) and VersionName not in(select VersionName from Version "
                + " where IsActive='1' and VersionID=(select VersionID from VersionPublish where "
                + " IsActive='1' and EMP_ID=(select EMPLOYEE_ID from SYS_LOGIN_DATA where ACTIVE='1' "
                + " and LOGINNAME='{2}' and PASSWORD='{3}'))) ", param);
                read = SqlData.ExecuteReader(SQL);
                while (read.Read())
                {
                    _VersionName = read["VersionName"].ToString();
                }
                read.Close();
            }
            return _VersionName;
        }
    }
}
